package ${package};

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import ${baseActionPackage};
import ${resultJsonPackage};
import ${modelPackage};
import ${servicePackage};
import com.tmsps.ne4spring.page.PageVo;
import com.nuoyun.pro.system.bean.ResultBean;
import com.nuoyun.pro.system.result.ApiResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

/**
 * @title ${className?cap_first}Action.java
 * @package ${package}
 * @description ${description}Action
 * @author ${author}
 * @date ${creatTime?string("yyyy-MM-dd")}
 * @version V1.0
 * @Copyright ${creatTime?string("yyyy")} nuoyun All rights reserved.
 */
@Api(value="${className?cap_first}Action",tags={"${tableName}"})
@RestController
@Scope("prototype")
@RequestMapping("${requestPrefix}/${tableSubName?uncap_first}/")
public class ${className?cap_first}Action extends BaseAction {

	@Autowired
	private ${className?cap_first}Service ${className?uncap_first}Service;
	
	/**
	 * @title get${tableSubName?cap_first}ListData
	 * @description 获取${description}列表数据
	 * @author ${author}
	 * @date ${creatTime?string("yyyy-MM-dd")}
	 * return ResultBean
	 */
	@ApiImplicitParams(value = { 
			@ApiImplicitParam(name = "pageNumber", defaultValue="1", value = "页码", required = true),
			@ApiImplicitParam(name = "pageSize", defaultValue="10", value = "每页显示条数,默认10", required = false)})
	@ApiOperation("获取${description}列表数据")
	@GetMapping(value = "get${tableSubName?cap_first}ListData")
	public ResultBean get${tableSubName?cap_first}ListData(int pageNumber,@RequestParam(value = "pageSize", required = false, defaultValue = "10") int pageSize) {
		PageVo<${tableName}> data = ${className?uncap_first}Service.get${tableSubName?cap_first}ListData(new PageVo<>(pageNumber,pageSize),srh);
		return ApiResponse.getResultPassOk(data);
	}
	
	<#if (saveorupdate=='true')>
	/**
	 * @title saveOrUpdate
	 * @description 添加、修改${description}
	 * @author ${author}
	 * @date ${creatTime?string("yyyy-MM-dd")}
	 * @param model
	 * return ResultBean
	 */
	@ApiOperation("添加、修改${description}")
	@PostMapping(value = "saveOrUpdate")
	public ResultBean saveOrUpdate(${tableName} model) {
		boolean result = ${className?uncap_first}Service.saveOrUpdate(model);
		return ApiResponse.getResult(result);
	}
	</#if>
	
	<#if (saveorupdate!='true')>
	/**
	 * @title save
	 * @description 添加${description}
	 * @author ${author}
	 * @date ${creatTime?string("yyyy-MM-dd")}
	 * @param model ${tableName}
	 * return ResultBean
	 */
	@ApiOperation("添加${description}")
	@PostMapping(value = "save")
	public ResultBean save(${tableName} model) {
		boolean result = ${className?uncap_first}Service.save(model);
		return ApiResponse.getResult(result);
	}
	
	/**
	 * @title update
	 * @description 修改${description}
	 * @author ${author}
	 * @date ${creatTime?string("yyyy-MM-dd")}
	 * @param model ${tableName}
	 * return ResultBean
	 */
	@ApiOperation("修改${description}")
	@PostMapping(value = "update")
	public ResultBean update(${tableName} model) {
		boolean result = ${className?uncap_first}Service.update(model);
		return ApiResponse.getResult(result);
	}
	</#if>
	/**
	 * @title getDetail
	 * @description 获取${description}列表数据
	 * @author ${author}
	 * @date ${creatTime?string("yyyy-MM-dd")}
	 * @param id ${tableSubName} id
	 * return ResultBean
	 */
	@ApiOperation("获取${description}列表数据")
	@GetMapping(value = "getDetail")
	public ResultBean getDetail(String id) {
		${tableName} detail = ${className?uncap_first}Service.get${tableSubName?cap_first}Model(id);
		return ApiResponse.getResultPassOk(detail);
	}
	
	/**
	 * @title remove
	 * @description 删除${description}
	 * @author ${author}
	 * @date ${creatTime?string("yyyy-MM-dd")}
	 * @param id ${description} id
	 * return ResultBean
	 */
    @ApiOperation("删除${description}")
	@PostMapping(value = "remove")
	public ResultBean remove(String id) {
		boolean result = ${className?uncap_first}Service.remove(id);
		return ApiResponse.getResult(result);
	}
	<#if (batch=='true')>
	/**
	 * @title deleteBatch
	 * @description 批量删除${description}
	 * @author ${author}
	 * @date ${creatTime?string("yyyy-MM-dd")}
	 * @param ids ${description} id列表
	 * return ResultBean
	 */
	@ApiOperation("批量删除${description}")
	@PostMapping(value = "deleteBatch")
	public ResultBean deleteBatch(String ids) {
		if (StrUtil.isBlank(ids)) {
			return ApiResponse.getResultExParam();
		}
		String[] idsArr = ids.split(",");
		boolean result = ${className?uncap_first}Service.batchRemove(Arrays.asList(idsArr));
		return ApiResponse.getResult(result);
	}
	</#if>
}